//
//  UITextField+Input.swift
//  AirlineReservation
//
//  Created by Kevin on 2019/12/26.
//  Copyright © 2019 Kevin. All rights reserved.
//

import UIKit

extension UITextField {
    
    convenience init(title:String = ""){
        self.init()
        // 文本
        // placeholder = title
        // 键盘类型
        keyboardType = .asciiCapable
        // 是否清除
        clearButtonMode = .whileEditing
        // 弱提示文本颜色
        attributedPlaceholder = NSAttributedString(string: title, attributes: [.foregroundColor : UIColor.lightGray])
    }
    
    convenience init(str:String,size:CGFloat,paddingLeft:CGFloat = MARGIN){
        self.init()
        text = str
        isEnabled = false
        font = UIFont.systemFont(ofSize: size)
        setValue(paddingLeft, forKey: "paddingLeft")
    }
    
    // 显示的图片混排
    func showTextEmoji(emoticon:Emoticon){
        // 空白表情
        if emoticon.isEmpty{
            return
        }
        // 删除按钮
        if emoticon.isRemove{
            deleteBackward()
            return
        }
        // emoji表情
        if let emoji = emoticon.code?.emoji{
            replace(selectedTextRange!, withText: emoji)
            return
        }
    }
}
